#ifndef __SEMAPORE_H__
#define __SEMAPORE_H__

#include <mutex>
#include <condition_variable>
#include <thread>
#include <iostream>

class Semaphore {
private:
    int count;
    std::mutex mutex;
    std::condition_variable cond;

public:
    Semaphore(int initial_count) : count(initial_count) {}
    Semaphore() : count(0) {}

    void acquire() {
        std::unique_lock<std::mutex> lock(mutex);
        cond.wait(lock, [this] { return count > 0; });
        --count;
    }

    void release() {
        std::lock_guard<std::mutex> lock(mutex);
        ++count;
        cond.notify_one();
    }
};

#endif